import org.learn.spring5.dao.UserDao;
import org.learn.spring5.dao.impl.MyInvocationHandler;
import org.learn.spring5.dao.impl.UserDaoImpl;

import java.lang.reflect.Proxy;

class TestProxy {

    public static void main(String[] args) {
        //被增强的类，真实的角色
        UserDaoImpl userDaoImpl = new UserDaoImpl();
        Class[] interfaces = {UserDao.class};  //接口
        //动态生成代理对象的实例并返回，传递谁就生产谁的代理对象
        UserDao dao = (UserDao) Proxy.newProxyInstance(TestProxy.class.getClassLoader(), userDaoImpl.getClass().getInterfaces(), new MyInvocationHandler(userDaoImpl));
        int res = dao.update(1);
        System.out.println(res);
    }
}
